package com.fang.牛客;

import java.util.*;
import java.util.stream.Collectors;

public class Demo3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Map<Integer, String> map = new HashMap<>();
        String line = in.nextLine();
        String[] lineArr = line.split(",");
        for (int i = 0, len = lineArr.length; i < len; i++) {
            map.put(i, lineArr[i]);
        }
        List<String> list = new LinkedList<>();
        Map<Integer, Integer> hash = new HashMap<>();
        for (int i = 0, len = lineArr.length; i < len; i++) {
            String grid = lineArr[i];
            for (int j = 0, gridLen = grid.length(); j < gridLen; j++) {
                char ch = grid.charAt(j);
                Integer key = Integer.parseInt(String.valueOf(ch));
                if (map.containsKey(key) && i != key) {
                    if (j == 0) j = 1;
                    grid = grid.substring(0, j) + map.get(key) + grid.substring(j);
                    hash.put(i, key);
                    break;
                }
            }
            list.add(grid);
            // 处理循环引用
            if (hash.containsKey(i) && hash.containsKey(hash.get(i)) && Objects.equals(i, hash.get(hash.get(i)))) {
                list.set(hash.get(i), lineArr[hash.get(i)]);
            }
        }
        String res = list.stream().collect(Collectors.joining(","));
        System.out.println(res);
    }
}
